﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kira.Compiler.Bods
{
    [XmlElementMapping("DITransformCall", "name", "Table_Comparison")]
    public class DITableComparison : BodsTransform
    {
        public String InputName
        {
            get
            {
                return this.GetElement("DIInputView").GetAttrbuteValue("name");
            }
        }

        public String OutputName
        {
            get
            {
                return this.GetElement("DISchema").GetAttrbuteValue("name");
            }
        }

        public String ComparisonDatastoreName
        {
            get
            {
                return this.GetElement("DIAttributes").GetElement(c => c.GetAttrbuteValue("name") == "database_datastore").GetAttrbuteValue("value");
            }
        }

        public String ComparisonOwnerName
        {
            get
            {
                return this.GetElement("DIAttributes").GetElement(c => c.GetAttrbuteValue("name") == "table_owner").GetAttrbuteValue("value");
            }
        }

        public String ComparisonTableName
        {
            get
            {
                return this.GetElement("DIAttributes").GetElement(c => c.GetAttrbuteValue("name") == "table_name").GetAttrbuteValue("value");
            }
        }

        public IEnumerable<String> ComparisonColumns
        {
            get
            {
                return from c in this.GetElement("DIAttributes").GetElements(c => c.GetAttrbuteValue("name").Contains("primary_key_column")) select c.GetAttrbuteValue("value");
            }
        }

        public override IEnumerable<string> InputNames
        {
            get { return new string[] { this.InputName }; }
        }

        public override IEnumerable<string> OutputNames
        {
            get { return new string[] { this.OutputName }; }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GetComments("Table_Comparison"));
            sb.AppendLine("--Table_Comparison not supported");
            return sb.ToString();
        }
    }
}
